package com.dykj.fireFighting.web.rocketmq.consumer;

import com.dykj.fireFighting.api.base.push.service.PushService;
import com.dykj.fireFighting.common.core.constant.WebsocketConstant;
import com.dykj.fireFighting.common.starter.redisson.service.RedisService;
import com.dykj.fireFighting.web.base.websocket.entity.MoreMessage;
import com.dykj.fireFighting.web.rocketmq.message.ZcPushMessage;
import com.dykj.fireFighting.web.utils.SpringUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zhengbo
 */
@RocketMQMessageListener(
        topic = ZcPushMessage.TOPIC,
        consumerGroup = "dy-consumer-group-" + ZcPushMessage.TOPIC
)
public class ZcPushConsumer implements RocketMQListener<ZcPushMessage> {
    public static final Logger LOGGER = LoggerFactory.getLogger(ZcPushConsumer.class);
    private static RedisService redisService= SpringUtil.getBean(RedisService.class);
    @Override
    public void onMessage(ZcPushMessage zcPushMessage) {
        String time = zcPushMessage.getAlarmTime();
        MoreMessage moreMessage=new MoreMessage();
        moreMessage.setMsgId(zcPushMessage.getDevHisId());
        moreMessage.setMsgTitle("电气火灾预警通知");
        moreMessage.setMsgTxt(zcPushMessage.getDeviceName() + "于" + time+ "发出预警信息请及时处理");
        moreMessage.setCmd(WebsocketConstant.CMD_ZC);
        moreMessage.setUserIds(zcPushMessage.getUnit().getUnitUserIds().toArray(new String[0]));
        redisService.convertAndSend("channel:moreMessage", moreMessage);
        moreMessage.setUserIds(zcPushMessage.getUnit().getCenterUserIds().toArray(new String[0]));
        moreMessage.setMsgTxt(zcPushMessage.getUnit().getUnitName() + "的" + zcPushMessage.getDeviceName() + "于" + time + "发出预警信息请及时处理");
        redisService.convertAndSend("channel:moreMessage", moreMessage);
    }
}
